// store/index.js (Vuex配置)
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        // 存储底部导航栏tabbar数据
        activeTabbar: 'asdasdasdasd',
        // activeTabbar: uni.getStorageSync('activeTabbar') || [],
        // 选中的tabbar tabbar的name值
        selectTab: uni.getStorageSync('selectTab') || 0,
    },
    mutations: {
        // 将底部导航栏tabbar数据存储到本地缓存中
        SET_TABBAR: (state, payload) => {
            state.activeTabbar = payload;
            uni.setStorageSync('activeTabbar', payload);
        },
        // 将当前选中的导航栏name值存储到本地缓存中
        SET_CURRENT_TAB: (state, val) => {
            state.selectTab = val;
            uni.setStorageSync('selectTab', val);
        }
    },
    actions: {
        // 设置当前选中tabbar
        setCurrentTab({
            commit
        }, val) {
            commit('SET_CURRENT_TAB', val);
        },
        // 设置底部tabbr
        SetTabbar({
            commit
        }, payload) {
            commit('SET_TABBAR', payload);
        }
    }

})